package com.example.clxy.controller;

import com.example.clxy.entity.Platform;
import com.example.clxy.interceptor.AppToken;
import com.example.clxy.result.PageResult;
import com.example.clxy.result.WebRestResult;
import com.example.clxy.result.business.PageResult.PlatformPageResult;
import com.example.clxy.result.business.PlatformResult;
import com.example.clxy.service.PlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author liuhaoqi
 * @Date 2020/8/4 15:10
 * @Version 1.0
 */
@AppToken
@RestController
@RequestMapping("PlatformController")
public class PlatformController {

    @Autowired
    PlatformService platformService;

    /**
     * 新增平台
     *
     * @param platform
     * @return
     */
    @CrossOrigin
    @PostMapping("addPlatform")
    public WebRestResult addPlatform(@RequestBody Platform platform) {
        WebRestResult result = platformService.addPlatform(platform);
        return result;
    }

    /**
     * @param platform
     * @return
     */
    @CrossOrigin
    @PostMapping("updatePlatform")
    public WebRestResult updatePlatform(@RequestBody Platform platform) {
        WebRestResult result = platformService.updatePlatform(platform);
        return result;
    }

    @CrossOrigin
    @PostMapping("deletePlatform")
    public WebRestResult deletePlatform(String platformid) {
        WebRestResult result = platformService.deletePlatform(platformid);
        return result;
    }

    @CrossOrigin
    @GetMapping("getPlatformList")
    public PageResult<PlatformPageResult> getPlatformList(String platformname, String platformintro, String credit,
                                                          String platformhour, int page, int pagesize,String status) {
        PageResult<PlatformPageResult> result = platformService.getPlatformList(platformname, platformintro, credit,
                platformhour, page, pagesize,status);
        return result;
    }

    @CrossOrigin
    @GetMapping("getPlatformById")
    public PlatformResult getPlatformById(String platformid) {
        PlatformResult result = platformService.getPlatformById(platformid);
        return result;
    }
}
